package classes;
import java.awt.Component;
import java.util.HashMap;
import java.util.Set;

public class HasProperties extends Component {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	
	private HashMap<String,Object>	properties = new HashMap<String,Object>();
	
	public static final Boolean isEquivelent(Object A, Object B) {
		if (A==null) {
			if (B==null) {
				return Boolean.TRUE;
			} else {
				return Boolean.FALSE;
			}
		} else {
			if (B==null) {
				return Boolean.FALSE;
			} else {
				return Boolean.valueOf(A.equals(B));
			}
		}
	}

	public final Boolean set(String propertyName, Object newValue) {
		//
		// We only ever reassign when we expect the objects to be different!
		//
		Object	oldValue = get(propertyName);
		
		if (!isEquivelent(oldValue,newValue)) {
			properties.put(propertyName, newValue);
			firePropertyChange(propertyName, oldValue, newValue);
			return Boolean.TRUE;
		} else {
			return Boolean.FALSE;
		}
	}

	public final Object get(String propertyName) {
		return properties.get(propertyName);
	}
	
	public final Set<String> getProperties() {
		return properties.keySet();
	}
	
	public final Boolean hasProperty(String propertyName) {
		return Boolean.valueOf(properties.containsKey(propertyName));
	}

}
